jQuery(document).ready(function(){
	jQuery(".country_select").change(function(){
		id = jQuery(this).attr('id');
		//jQuery("select#state_"+id).html('');
		//jQuery("select#state_"+id).trigger("liszt:updated");
		//jQuery("select#province_state_"+id).html('');
		//jQuery("select#province_state_"+id).trigger("liszt:updated");
		//jQuery("select#city_state_"+id).html('');
		//jQuery("select#city_state_"+id).trigger("liszt:updated");
		
		country_id = jQuery(this).val();
		jQuery.post("./admin/be_listing_place/get_state_data", { country_id: jQuery(this).val()},
			function(data){
				if(data.spain){
					jQuery("#province_state_"+id+"_wrapper").css("display", "block");
				}else{
					jQuery("#province_state_"+id+"_wrapper").css("display", "none");
					        
				}
				jQuery("select#state_"+id).html(data.data);
				jQuery("select#state_"+id).trigger("liszt:updated");
			}, "json");
	});
	
	jQuery(".state_select").change(function(){
		id = jQuery(this).attr('id');
		country_id = jQuery("#"+id.substr(6, id.length)).val();
		state_id = jQuery(this).val();
		jQuery.post("./admin/be_listing_place/get_city_data", { country_id: country_id, state_id: state_id},
			function(data){
				if(data.spain){
					jQuery("select#province_"+id).html(data.data);
					jQuery("select#province_"+id).trigger("liszt:updated");
					jQuery("#province_"+id+"_wrapper").css("display", "block");
				}else{
					jQuery("select#city_"+id).html(data.data);
					jQuery("select#city_"+id).trigger("liszt:updated");
				}
			}, "json");
	});
	jQuery(".provice_select").change(function(){
		id = jQuery(this).attr('id');
		country_id = jQuery("#"+id.substr(15, id.length)).val();
		state_id = jQuery("#"+id.substr(9, id.length)).val();
		province_id = jQuery(this).val();
		jQuery.post("./admin/be_listing_place/get_spain_city_data", { country_id: country_id, state_id: state_id, province_id: province_id},
			function(data){
				jQuery("select#city_"+id.substr(9, id.length)).html(data.data);
				jQuery("select#city_"+id.substr(9, id.length)).trigger("liszt:updated");
			}, "json");
	});
});